package wq.gdky005.main.db;

import wq.gdky005.app.GlobleConstant;
import wq.gdky005.main.service.DBCenter;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;


public class MainDB extends DBCenter {

	private final String[] MAIN_TAB_ALLROW = new String[] {
			GlobleConstant.MAIN_ID, GlobleConstant.MAIN_CODE,
			GlobleConstant.MAIN_CITY };

	public MainDB(Context context) {
		super(context);
		upgradeDatabase();
	}

	/**
	 * 插入数据 wangqing 2013-5-27 long
	 * 
	 * @param contentValues
	 * @return
	 */
	public long insertData(ContentValues contentValues) {
		return insert(GlobleConstant.MAIN_TABLE, contentValues);
	}

	/**
	 * 删除数据 wangqing 2013-5-27 boolean
	 * 
	 * @param id
	 * @return
	 */
	public boolean deleteData(String id) {
		return delete(GlobleConstant.MAIN_TABLE, GlobleConstant.MAIN_CODE
				+ "='" + id + "'", null) > 0;
	}

	/**
	 * 更新数据 wangqing 2013-5-27 boolean
	 * 
	 * @param id
	 * @param city
	 * @return
	 */
	public boolean updateData(String id, String city) {
		ContentValues values = new ContentValues();
		values.put(GlobleConstant.MAIN_CITY, city);
		return update(GlobleConstant.MAIN_TABLE, values,
				GlobleConstant.MAIN_CODE + "='" + id + "'", null) > 0;
	}

	/**
	 * 查询数据 wangqing 2013-5-27 Cursor
	 * 
	 * @param id
	 * @return
	 */
	public Cursor queryData(String city) {
		Cursor cursor = query(GlobleConstant.MAIN_TABLE, MAIN_TAB_ALLROW,
				GlobleConstant.MAIN_CITY + "='" + city + "'", null, null);

		return cursor;
	}
}
